module.exports = (app) => {
  const { AdminMenu } = app.model

  const menuList = [
    {
      menuName: '系统管理',
      icon: 'fa fa-cog',
      // icon: 'el-icon-setting',
      systemType: 'admin',
      isOpen: true,
      children: [
        {
          menuName: '菜单管理',
          rank: 99,
          path: '/system/menu',
        },
        {
          menuName: '系统用户',
          path: '/system/user',
        },
        {
          menuName: '角色管理',
          path: '/system/role',
        },
        {
          menuName: '密码修改',
          path: '/system/modify-password',
        },
        {
          menuName: '配置管理',
          path: '/system/config',
        },
        {
          menuName: '系统设置',
          path: '/system/setting',
        },
      ],
    },
  ]

  menuList.map(async (item) => {
    const parent = await AdminMenu.findOneAndUpdate(
      {
        menuName: item.menuName,
      },
      {
        ...item,
        systemType: 'admin',
      },
      {
        upsert: true,
        new: true,
      }
    )

    if (item.children) {
      item.children.map(async (item) => {
        await AdminMenu.findOneAndUpdate(
          {
            menuName: item.menuName,
          },
          {
            parentId: parent._id,
            systemType: parent.systemType,
            isOpen: parent.isOpen,
            ...item,
          },
          {
            upsert: true,
            new: true,
          }
        )
      })
    }
  })
}
